import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// WindiCSS
import WindiCSS from 'vite-plugin-windicss'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    WindiCSS(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        // silenceDeprecations: ["legacy-js-api"],
        // 定义颜色
        additionalData: '@use "@/assets/scss/color.scss" as *;' +
          '@use "@/assets/scss/size.scss" as *;'
      }
    }
  },
  server: {
    port: 6102,
    proxy: {
      '/api': {
        target: 'http://localhost:6101',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '/admin')
      }
    }
  },
  build: {
    chunkSizeWarningLimit: 1000,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString()
          }
        }
      }
    }
  }
})
